import { NotFound } from 'lin-mizar';
import { Music } from '../model/music';

class MusicDao {

  static async getMusicList(){
    return await Music.findAll();
  }

  static async addMusic(v){
    return await Music.create(v);
  }

  static async editMusic(id, v){
    const music = await Music.findByPk(id);
    if(!music){
      throw new NotFound();
    }

    return await music.update({...v});
  }

  static async deleteMusic(id){
    const music = await Music.findByPk(id);
    if(!music){
      throw new NotFound();
    }

      return await Music.destroy({
      where: {
        id
      }
    })
  }
}

export { MusicDao };
